package common

import (
	"code.huawei.com/tdc-sdk/utils"
	"github.com/dgrijalva/jwt-go"
	"nft-server/config"
	"nft-server/logger"
	"time"
)

const (
	BlockChainSharedMode  = "shared"
	BlockChainPrivateMode = "private"
)

var (
	// Captcha sesssion中的验证码的name
	SessionCaptchaName = "captcha"
	// Session中的key
	SessionUserId     = "userId"
	SessionUserName   = "userName"
	SessionRole       = "role"
	SessionPwdChanged = "passchanged"

	// 用户密码的加密
	Iter           = 5000
	KeyLength      = 8
	BlockChainType string
)

func init() {
	// 加载blockChain类型
	dacConfig, err := utils.NewConfig(config.GetConfig().DACConfig.ConfigPath)
	if err != nil {
		logger.Error("load dac config file error: %v", err)
		return
	}
	BlockChainType = dacConfig.Service.Type
}

// MetaData 生成的每一张图片的metaData数据，以json的格式存储在文件系统中
type MetaData struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Image       string      `json:"image"`
	Attributes  []Attribute `json:"attributes"`
}

// Attribute 图片的组成部分 通过probability.go中的map[CollectionName][Attribute]可以查询到component的出现的概率
type Attribute struct {
	TraitType string `json:"trait_type"`
	Value     string `json:"value"`
}

type Survey struct {
	Q1 string `json:"1"`
	Q2 string `json:"2"`
	Q3 string `json:"3"`
	Q4 string `json:"4"`
	Q5 string `json:"5"`
	Q6 string `json:"6"`
	Q7 string `json:"7"`
	Q8 string `json:"8"`
}

type CommonParam struct {
	Cert       string `json:"cert"`
	SignedData string `json:"signed_data"`
	Data       string `json:"data"`
}

type Captcha struct {
	// 验证码内容
	Content string `json:"content"`
	// 验证码创建时间
	CreateDate time.Time `json:"createDate"`
	// 当前session请求验证码的次数
	RequestTimes int `json:"requestTimes"`
	// 当前验证码是否已被使用
	Used bool `json:"used"`
}

type LoginUserInfo struct {
	Id       int    `json:"id"`
	Name     string `json:"name"`
	Password string `json:"password"`
	Salt     string `json:"salt"`
	// 连续登录失败次数
	FailTimes int `json:"failTimes"`
	//账号是否被锁定
	Locked bool `json:"locked"`
	// 上一次锁定时间
	LockedTime time.Time `json:"lockedTime"`
	// 角色id  这里创建的外键需要注意
	Role       string `json:"role"`
	PwdChanged bool   `json:"pwdChanged"`
	//是否已经实名认证
	Authenticated bool `json:"authenticated"`
}

type PhoneVerificationInfo struct {
	Code       string `json:"verificationCode"`
	CdTime     int64  `json:"cooldownTime"`
	ExpireTime int64  `json:"expireTime"`
	FailTimes  int    `json:"failTime"`
}

type Claims struct {
	SessionId string `json:"sessionId"`
	jwt.StandardClaims
}

//修改collection参数
type ModifyCollectionDetail struct {
	UserId                int
	CollectionIndex       string
	SubCollectionIndex    int
	QueryCollectionStatus []int
	CollectionName        *string
	SaleTime              *time.Time
	OffShelfTime          *time.Time
	Price                 *float64
	AfterCollectionStatus *int
}

//查询collection参数
type QueryCollectionDetail struct {
	UserId             *int
	CollectionIndex    []string
	CollectionStatus   []int
	SubCollectionIndex *int
	NeedMainCollection *bool
	CollectionName     *string
	Issuer             *string
	Page               *int
	PageSize           *int
	NowTime            *time.Time
	Distinct           *bool
}

//查询user参数
type QueryUserDetail struct {
	UserId      *int
	UserName    *string
	PhoneNumber *string
	Address     *string
}

//查询user参数
type QueryUserNum struct {
	UserName *string
	Locked   *bool
}

type QueryUserList struct {
	Offset   int
	PageSize int
	UserName *string
	Locked   *bool
}

type ModifyUserDetail struct {
	UserId           int
	Password         *string
	Salt             *string
	PwdChanged       *bool
	Authenticated    *bool
	AssetObtainedNum *int
	ProfilePhotoUrl  *string
	Lock             *bool
	FailTimes        *int
	LockTime         *time.Time
	PhoneNumber      *string
}

type QueryBurnAssetInfo struct {
	CollectionIndex    string
	SubCollectionIndex *int
}

type CollectionIdentity struct {
	CollectionIndex    string
	SubCollectionIndex int
}
